from flask import Blueprint, jsonify, request
from app.services.ros_service import RosService

def init_ros_routes(ros_utils, launch_files):
    ros_bp = Blueprint('ros', __name__)
    ros_service = RosService(ros_utils, launch_files)
    
    @ros_bp.route('/status', methods=['POST'])  # 完整路径: /api/ros/status
    def ros_node_status():
        data = request.get_json()
        if not data or 'status' not in data:
            return jsonify({
                "code": 400,
                "message": "缺少status参数",
                "data": None
            }), 200
        status = data['status']
        result = ros_service.control_nodes(status)
        return jsonify(result), result["code"]
    
    return ros_bp